#!/usr/bin/python
# -*- coding: UTF-8 -*-

from kpautos.engine.case import Case
from kptest.config.enum import DeviceType, HostType, DeviceUtility


class BMC_SSH_014(Case):
    """
        Name:
            BMC_SSH_014
        Label:
            验证CLI接口可以配置紧急用户
        PreCondition:
            1、BMC正常运行
        TestStep:
            1.	登录BMC
            2.	设置紧急用户，有结果A）
            iBMC:/->ipmcset -d emergencyuser -v username
        ExpectedResult:
            A）命令执行成功，无报错信息
        Parameters:

        Remark:

    """

    # 测试执行前配置等准备操作
    def pre_test_case(self):
        self.device_dut = self.resource.get_device(device_type=DeviceType.Server, utility=DeviceUtility.DUT)
        self.bmc_host = self.device_dut.get_host(host_type=HostType.BMC)
        self.bmc_user = self.bmc_host.username

    # 测试步骤
    def procedure(self):
        self.log_step(f"1、设置用户{self.bmc_user}为紧急用户")
        resp = self.bmc_host.run({"command": [f"ipmcset -d emergencyuser -v {self.bmc_user}"], "timeout": 3})
        self.log_info(resp)
        if resp['rc'] != 0:
            self.assertIsNotNone(None, f"{resp['stderr']}")

    # 测试结束后恢复环境
    def post_test_case(self):
        pass